From 9215ceafc0c8323a0200f2128682c6d6137066ff Mon Sep 17 00:00:00 2001 From: Robert Lipe Date: Sun, 2 Dec 2018 23:45:25 -0600 Subject: [PATCH] Modernize loop iterators to walk arrays and containes instead of independently maintained constants. --- alan.cc | 20 ++++++++++---------- an1.cc | 8 ++++---- f90g_track.cc | 8 ++++---- garmin_fit.cc | 4 ++-- jeeps/gpsserial.h | 7 +++---- mkshort.cc | 8 ++++---- rgbcolors.cc | 10 +++++----- shape.cc | 4 ++-- skytraq.cc | 4 ++-- tpo.cc | 4 ++-- vecs.cc | 6 +++--- 11 files changed, 41 insertions(+), 42 deletions(-) diff --git a/alan.cc b/alan.cc index 7d0c638fa..bc5e326ae 100644 --- a/alan.cc +++ b/alan.cc @@ -236,8 +236,8 @@ static void swap_wpthdr(struct wpthdr* wpthdr, if (swap16_func != nullptr) { swap16_func(&wpthdr->num); swap16_func(&wpthdr->next); - for (int i=0; iidx[i]); + for (short &i : wpthdr->idx) { + swap16_func(&i); } } } @@ -262,8 +262,8 @@ static void swap_rtehdr(struct rtehdr* rtehdr, if (swap16_func != nullptr) { swap16_func(&rtehdr->num); swap16_func(&rtehdr->next); - for (int i=0; iidx[i]); + for (short &i : rtehdr->idx) { + swap16_func(&i); } swap16_func(&rtehdr->rteno); } @@ -277,8 +277,8 @@ static void swap_rte(struct rte* rte, { if (swap16_func != nullptr) { swap16_func(&rte->wptnum); - for (int i=0; iwptidx[i]); + for (short &i : rte->wptidx) { + swap16_func(&i); } swap16_func(&rte->reserved); } @@ -350,8 +350,8 @@ static void swap_loghdr(struct loghdr* loghdr, swap32_func(&(loghdr->date)); swap32_func(&(loghdr->time)); } - for (int i = 0; itrkhdr[i]), swap16_func, swap32_func); + for (auto &i : loghdr->trkhdr) { + swap_trkhdr(&i, swap16_func, swap32_func); } } @@ -400,8 +400,8 @@ static void trl_swap(struct trldata* trldata) } swap_loghdr(&(trldata->loghdr), swap16_func, swap32_func); - for (int i = 0; itrklog[i]), swap16_func, swap32_func); + for (auto &i : trldata->trklog) { + swap_trklog(&i, swap16_func, swap32_func); } } diff --git a/an1.cc b/an1.cc index a3d29010b..f2492bdc4 100644 --- a/an1.cc +++ b/an1.cc @@ -130,11 +130,11 @@ static void ReadGuid(gbfile* f, GUID* guid) { guid->l = ReadLong(f); - for (int i = 0; i < 3; i++) { - guid->s[i] = ReadShort(f); + for (unsigned short &i : guid->s) { + i = ReadShort(f); } - for (int i = 0; i < 6; i++) { - guid->c[i] = ReadChar(f); + for (unsigned char &i : guid->c) { + i = ReadChar(f); } } diff --git a/f90g_track.cc b/f90g_track.cc index f5c5588b6..01d70699a 100644 --- a/f90g_track.cc +++ b/f90g_track.cc @@ -61,8 +61,8 @@ f90g_track_rd_init(const QString& fname) fatal(MYNAME ": read error"); } else { // flip bits and check for valid header - for (int i = 0; ifields) { xfree(def->fields); def->fields = nullptr; diff --git a/jeeps/gpsserial.h b/jeeps/gpsserial.h index a9f13dae3..80ddaf8e7 100644 --- a/jeeps/gpsserial.h +++ b/jeeps/gpsserial.h @@ -20,9 +20,8 @@ // int32 GPS_Serial_On_NMEA(const char *port, gpsdevh **fd); int32 GPS_Serial_Read(gpsdevh* fd, void* ibuf, int size); int32 GPS_Serial_Write(gpsdevh* fd, const void* obuf, int size); - int32 GPS_Serial_Write_Packet(gpsdevh* fd, GPS_PPacket& packet); - int32 GPS_Serial_Send_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec); - void GPS_Serial_Error(const char* hdr, ...); - int32 GPS_Serial_Set_Baud_Rate(gpsdevh* fd, int br); + + +int32 GPS_Serial_Set_Baud_Rate(gpsdevh* fd, int br); #endif diff --git a/mkshort.cc b/mkshort.cc index 86a2a061d..19e62aaf3 100644 --- a/mkshort.cc +++ b/mkshort.cc @@ -85,8 +85,8 @@ mkshort_new_handle() { mkshort_handle_imp* h = (mkshort_handle_imp*) xcalloc(sizeof *h, 1); - for (int i = 0; i < PRIME; i++) { - QUEUE_INIT(&h->namelist[i]); + for (auto &i : h->namelist) { + QUEUE_INIT(&i); } h->whitespaceok = 1; @@ -160,9 +160,9 @@ mkshort_del_handle(short_handle* h) return; } - for (int i = 0; i < PRIME; i++) { + for (auto &i : hdr->namelist) { queue* e, *t; - QUEUE_FOR_EACH(&hdr->namelist[i], e, t) { + QUEUE_FOR_EACH(&i, e, t) { uniq_shortname* s = reinterpret_cast(e); #if 0 if (global_opts.verbose_status >= 2 && s->conflictctr) { diff --git a/rgbcolors.cc b/rgbcolors.cc index bf939bb23..7db6c3ddd 100644 --- a/rgbcolors.cc +++ b/rgbcolors.cc @@ -236,11 +236,11 @@ color_to_bbggrr(const char* opt_color) return color_num; } - for (unsigned int i = 0; i < sizeof(color_table) / sizeof(color_table[0]); i++) { - if (0 == case_ignore_strcmp(opt_color, color_table[i].cn)) { - return (color_table[i].b << 16) + - (color_table[i].g << 8) + - color_table[i].r; + for (auto i : color_table) { + if (0 == case_ignore_strcmp(opt_color, i.cn)) { + return (i.b << 16) + + (i.g << 8) + + i.r; } } diff --git a/shape.cc b/shape.cc index 1f51a6352..bdc2961dc 100644 --- a/shape.cc +++ b/shape.cc @@ -300,10 +300,10 @@ my_read() // } else if (nameidx == -1) { // leave name as a null QString. } else if (nameidx == -2) { - for (int oidx=0; oidx255)) { col = 0; // assign black if out of range 0x00 to 0xff } - styles[ii].color[xx] = (uint8_t)col; + xx = (uint8_t)col; } unsigned char tmp = gbfgetc(tpo_file_in); diff --git a/vecs.cc b/vecs.cc index 940f2e918..5f5d95f1a 100644 --- a/vecs.cc +++ b/vecs.cc @@ -1602,9 +1602,9 @@ disp_v1(ff_type t) static void disp_v2(ff_vecs_t* v) { - for (int i = 0; i < 3; i++) { - putchar((v->cap[i] & ff_cap_read) ? 'r' : '-'); - putchar((v->cap[i] & ff_cap_write) ? 'w' : '-'); + for (auto &i : v->cap) { + putchar((i & ff_cap_read) ? 'r' : '-'); + putchar((i & ff_cap_write) ? 'w' : '-'); } putchar('\t'); } -- 2.30.2